import { usePageRequest } from "../../utils/request";
import dayjs from "../../utils/day";

Component({
    properties: {},
    data: {
        status: 0,
    },
    methods: {
        onLoad() {
            // 房源
            this.house = new usePageRequest('api/usercollecthouselist', {}, this)
            // 房东
            this.landlord = new usePageRequest('api/usercollecthouseownerlist', { hold: true }, this)
            // 攻略
            this.strategy = new usePageRequest('api/usercollectstragylist', {
                hold: true,
                pretreatment: data => {
                    data.list = data.list.map(item => {
                        item.time = dayjs.unix(item.time).format('YYYY-MM-DD')
                        return item
                    })
                    return data
                }
            }, this)
            // 旅游圈
            this.dynamic = new usePageRequest('api/usercollecttouriselist', { hold: true }, this)
        },
        changeStatus(e) {
            const index = Number(e.detail.index)
            this.setData({
                status: index
            })
            wx.startPullDownRefresh()
        },
        onPullDownRefresh() {
            switch (this.data.status) {
                case 0:
                    this.house.reset().then(() => {
                        wx.stopPullDownRefresh()
                    })
                    break;
                case 1:
                    this.landlord.reset().then(() => {
                        wx.stopPullDownRefresh()
                    })
                    break;
                case 2:
                    this.strategy.reset().then(() => {
                        wx.stopPullDownRefresh()
                    })
                    break;
                case 3:
                    this.dynamic.reset().then(() => {
                        wx.stopPullDownRefresh()
                    })
                    break;
            }
        },
        onReachBottom() {
            switch (this.data.status) {
                case 0:
                    this.house.next()
                    break;
                case 1:
                    this.landlord.next()
                    break;
                case 2:
                    this.strategy.next()
                    break;
                case 3:
                    this.dynamic.next()
                    break;
            }
        },
    }
});
